package com.zxbg.controller.loginController;

import com.zxbg.controller.Code;
import com.zxbg.controller.Result;
import com.zxbg.domain.Employee;
import com.zxbg.domain.Login;
import com.zxbg.service.loginService.LoginService;
import com.zxbg.service.systemtoolsService.SecurityManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@RestController
@RequestMapping("/login")
public class loginController {
    @Autowired
    private LoginService loginService;
    @Autowired
    SecurityManagementService securityManagementService;

    @PostMapping
    public Result getEmployeeByEmployeeIdAndPassword(@RequestBody Employee employee) {
        Employee target_employee = loginService.getEmployeeByEmployeeIdAndPassword(employee.getEmployee_id(), employee.getLogin_password(), employee.getTenant_id());
        Integer code = target_employee != null ? Code.GET_OK : Code.GET_ERR;
        Login data = target_employee != null ? new Login(target_employee, UUID.randomUUID()) : null;
        String message = target_employee != null ? "" : "账号或密码错误";
        return new Result(code, data, message);
    }

    @GetMapping("/{tenant_id}")
    public Result getIfNeedCanvas(@PathVariable Integer tenant_id) {
        return new Result(Code.GET_OK, securityManagementService.getLoginCodeByTenantId(tenant_id));
    }
}
